package com.beyond.pratice.service.impl;

import com.beyond.pratice.service.UserService;
import com.beyond.pratice.model.User;
import com.beyond.pratice.utils.Page;
import com.beyond.pratice.dao.HibernateEntityExtendDao;
import org.hibernate.Criteria;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.MatchMode;

/**
 * User: lewisw
 * Date: 2008-3-5
 * Time: 15:40:14
 */
public class UserServiceImpl extends HibernateEntityExtendDao<User> implements UserService {

    public void save(User user) {
        super.save(user);
    }

    public Page<User> getUsers(String username, String email, Page<User> page) {
        Criteria criteria = createCriteria(User.class);
        if (username != null && !username.trim().equals("")) {
            criteria.add(Property.forName("username").like(username, MatchMode.ANYWHERE));
        }
        if (email != null && !email.trim().equals("")) {
            criteria.add(Property.forName("email").like(email, MatchMode.ANYWHERE));
        }
        return pagedQuery(criteria, page.getCurrentPageNo(), page.getPageSize());
    }
}
